package com.sy.demo.dom4j;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

/**
 * 
 * Description:该类演示最基本的Dom4j使用 
 * Copyright (c) Department of Research and Development/Beijing/W-Ya.
 * All Rights Reserved.
 * @version 1.0  Jun 19, 2010 6:18:58 PM  by 孙玮男（lukesun89@gmail.com）创建
 */
public class Dom4jBase {

	public Dom4jBase() {
	}

	/**
	 * 
	 * Description:该类演示如何使用dom4j创建最基本的xml结构,我们将使用代码创建如下结构的xml
	 * <root>
	 *  <name>
	 *  	Cacti
	 *  </name>
	 * </root> 
	 * @Version1.0 Jun 19, 2010 6:24:15 PM by 孙玮男（lukesun89@gmail.com）创建
	 * @throws DocumentException 
	 */
	public void buildXML() throws DocumentException
	{
		Document doc = DocumentHelper.parseText("<root/>");
		//Document doc = DocumentHelper.parseText("<root></root>");
		//Document对象创建的方式是多种多样的,建议查看api.
		Element name = doc.getRootElement().addElement("name");
		name.setText("Cacti");
		System.out.println(doc.asXML());
	}
}
